package com.travel.travel_springboot_web.mapper;

import com.travel.travel_springboot_web.entity.OrderGoods;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;

@Mapper
public interface OrderGoodsMapper {
    @Insert("INSERT INTO order_goods (order_id, goods_id, goods_title, goods_image, goods_price, " +
            "num, gift_num, total_price, gift_rule_text, created_at) " +
            "VALUES (#{orderId}, #{goodsId}, #{goodsTitle}, #{goodsImage}, #{goodsPrice}, " +
            "#{num}, #{giftNum}, #{totalPrice}, #{giftRuleText}, NOW())")
    int insert(OrderGoods orderGoods);
    
    @Select("SELECT og.*, g.cover_image as goods_image " +
            "FROM order_goods og " +
            "LEFT JOIN goods g ON og.goods_id = g.id " +
            "WHERE og.order_id = #{orderId}")
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "orderId", column = "order_id"),
        @Result(property = "goodsId", column = "goods_id"),
        @Result(property = "goodsTitle", column = "goods_title"),
        @Result(property = "goodsImage", column = "goods_image"),
        @Result(property = "goodsPrice", column = "goods_price"),
        @Result(property = "num", column = "num"),
        @Result(property = "giftNum", column = "gift_num"),
        @Result(property = "totalPrice", column = "total_price"),
        @Result(property = "giftRuleText", column = "gift_rule_text"),
        @Result(property = "createdAt", column = "created_at")
    })
    List<OrderGoods> findByOrderId(Long orderId);
} 